/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.cms.service;

import java.util.List;

import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.sys.dao.OfficeDao;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.cms.entity.BusinessRepairs;
import com.thinkgem.jeesite.modules.cms.dao.BusinessRepairsDao;

/**
 * 报修表生成Service
 * @author 开发者
 * @version 2016-06-18
 */
@Service
@Transactional(readOnly = true)
public class BusinessRepairsService extends CrudService<BusinessRepairsDao, BusinessRepairs> {

    @Autowired
    private OfficeDao officeDao;

	public BusinessRepairs get(String id) {
		return super.get(id);
	}
	
	public List<BusinessRepairs> findList(BusinessRepairs businessRepairs) {
		return super.findList(businessRepairs);
	}
	
	public Page<BusinessRepairs> findPage(Page<BusinessRepairs> page, BusinessRepairs businessRepairs) {
        if (businessRepairs.getOffice()!=null && StringUtils.isNotBlank(businessRepairs.getOffice().getId()) && !Office.isRoot(businessRepairs.getOffice().getId())){
            Office office = officeDao.get(businessRepairs.getOffice().getId());
            if (office==null){
                office = new Office();
            }
            office.setParentIds(office.getId());
//            category.setSite(category.getSite());
            businessRepairs.setOffice(office);
        }
        else{
            businessRepairs.setOffice(new Office());
        }
		return super.findPage(page, businessRepairs);
	}
	
	@Transactional(readOnly = false)
	public void save(BusinessRepairs businessRepairs) {

        super.save(businessRepairs);
	}
	
	@Transactional(readOnly = false)
	public void delete(BusinessRepairs businessRepairs) {
		super.delete(businessRepairs);
	}
	
}